//
//  LSOtherHomePageViewController.m
//  LookScore
//
//  Created by warrior on 2018/5/30.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSOtherHomePageViewController.h"
#import "LSHttpEnclosureTool.h"
#import <MJRefresh.h>
#import "LSPersonalHomePageHeadView.h"
#import "LSPersonalHomePageCharmCell.h"
#import "LSChatCircleCell.h"//聊天圈和发布话题一样cell
#import "LSChatCircleModel.h"
#import "LSPersonalHomePageCharmModel.h"
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "LSAccountArchive.h"
#import "LSEditIntroduceViewController.h"
#import "WRNavigationBar.h"
#import "ConversationDetailController.h"
#import "LSPersonalHomePageVController.h"
#import "YBPopupMenu.h"
@interface LSOtherHomePageViewController ()<UITableViewDelegate,UITableViewDataSource,LSPersonalHomePageCharmCellDelagate,YBPopupMenuDelegate>
{
    LSPersonalHomePageHeadView *headView;
//    NSString * _tokenStr;
}

@property(strong,nonatomic)UITableView *tableView;

@property(strong,nonatomic)NSMutableArray *modelArray;
//@property (nonatomic, strong) NSMutableArray * publishCycleArray;
//@property (nonatomic, strong) NSMutableArray * joinCycleArray;
//@property (nonatomic, )

@property(assign,nonatomic)NSInteger  chooseTag;

@property(assign,nonatomic)NSInteger  pageIndex;

@property(assign,nonatomic)NSInteger  queryType;//1关注 2粉丝
@end

@implementation LSOtherHomePageViewController

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor =LSBackGroundColor;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}


- (NSMutableArray *)modelArray{
    if(!_modelArray){
        _modelArray = @[].mutableCopy;
    }
    return _modelArray;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent=YES;
    
    
}
//-(void)viewDidDisappear:(BOOL)animated{
//    [super viewDidDisappear:YES];
//    self.navigationController.navigationBar.hidden=NO;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = LSTitleWhiteColor;
    
    
    UIButton *reportButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,22,22)];
    [reportButton setBackgroundImage:[UIImage imageNamed:@"report"] forState:UIControlStateNormal];
    [reportButton addTarget:self action:@selector(clickReportBu:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightBarBuI = [[UIBarButtonItem alloc] initWithCustomView:reportButton];
    self.navigationItem.rightBarButtonItem = rightBarBuI;
    
    
//    _tokenStr = [LSAccountArchive isLogin] ? [LSAccountArchive account].Cid : @"";
    [self wr_setNavBarBackgroundAlpha:0];
    self.chooseTag = 0;
    [self loadTopViewData];
    
    
    LSRefreshHeaderView *header = [LSRefreshHeaderView headerWithRefreshingBlock:^{
        [self loadTableViewData:YES];
        
    }];
    self.tableView.mj_header = header;// 设置header
    [header beginRefreshing];
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [self loadTableViewData:NO];
    }];
    
    [notifiCenter addObserver:self selector:@selector(updateUserInfo) name:@"LOADCIRCLEDATA" object:nil];
    
}
- (void)updateUserInfo{
    [self loadTopViewData];
    [self loadTableViewData:YES];
}

-(void)loadTopViewData{
    //    headView.bottomArray = nil;
    //    [headView.bottomArray removeAllObjects];
    NSDictionary *userIndexInfoDic=@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid};
    [LSHttpEnclosureTool GET:LSUserIndexInfo parameters:userIndexInfoDic resBlock:^(id responseObject) {
        if (responseObject) {
            MyLog(@"topViewData = %@",responseObject);
            [self initTopUIWithData:responseObject];
//            [self setData:responseObject];
        }
    }];
}
- (void)loadTableViewData:(BOOL)refresh{
    if (refresh) {
        
        self.pageIndex = 0;
    }else{
        
        self.pageIndex += 1;
    }
    
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    //    hud.label.text=@"正在请求中...";
    hud.mode=MBProgressHUDModeIndeterminate;
    //    self.pageIndex = 0;
    if (self.chooseTag == 0) {
        [LSHttpEnclosureTool GET:LSPublishList parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex)} resBlock:^(id responseObject) {
            if (refresh) {
                [self.modelArray removeAllObjects];
            }
            if (responseObject) {
                for (NSDictionary * dict in responseObject[@"TopicList"]) {
                    LSChatCircleModel *model = [LSChatCircleModel mj_objectWithKeyValues:dict];
                    
                    [self.modelArray addObject:model];
                }
            }else{
                
                self.pageIndex -= 1;
                
            }
            [hud hideAnimated:YES];
            MyLog(@"tableViewData:%@",responseObject);
            [self.tableView reloadData];
            [CommonClass endRefreshing:self.tableView];
        }];
        
    }else if (self.chooseTag == 1){
        
        [LSHttpEnclosureTool GET:LSJoinList parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex)} resBlock:^(id responseObject) {
            if (refresh) {
                [self.modelArray removeAllObjects];
            }
            if (responseObject) {
                for (NSDictionary * dict in responseObject[@"JoinList"]) {
                    MyLog(@"LSJoinList --- %@",responseObject);
                    LSChatCircleModel *model = [LSChatCircleModel mj_objectWithKeyValues:dict];
                    [self.modelArray addObject:model];
                }
            }else{
                
                self.pageIndex -= 1;
                
            }
            [hud hideAnimated:YES];
            //            MyLog(@"tableViewData:%@",responseObject);
            [self.tableView reloadData];
            [CommonClass endRefreshing:self.tableView];
        }];
        
    }else if (self.chooseTag == 2){
        self.queryType = 1;
        
        [LSHttpEnclosureTool GET:LSUSerFans parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex),@"type":@(self.queryType)} resBlock:^(id responseObject) {
            if (refresh) {
                [self.modelArray removeAllObjects];
            }
            MyLog(@"tableViewData:%@",responseObject);
            if (responseObject) {
                for (NSDictionary * dict in responseObject[@"UserList"]) {
                    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dict];
                    [dic setObject:@(self.queryType) forKey:@"queryType"];
                    LSPersonalHomePageCharmModel *model = [LSPersonalHomePageCharmModel mj_objectWithKeyValues:dict];
                    
                    [self.modelArray addObject:model];
                    //                    MyLog(@"tableViewData:%@",dic);
                }
                
            }else{
                
                self.pageIndex -= 1;
                
            }
            [hud hideAnimated:YES];
            [self.tableView reloadData];
            [CommonClass endRefreshing:self.tableView];
        }];
        
    }else if (self.chooseTag == 3){
        self.queryType = 2;
        
        [LSHttpEnclosureTool GET:LSUSerFans parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex),@"type":@(self.queryType)} resBlock:^(id responseObject) {
            if (refresh) {
                [self.modelArray removeAllObjects];
            }
            if (responseObject) {
                for (NSDictionary * dict in responseObject[@"UserList"]) {
                    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dict];
                    [dic setObject:@(self.queryType) forKey:@"queryType"];
                    
                    LSPersonalHomePageCharmModel *model = [LSPersonalHomePageCharmModel mj_objectWithKeyValues:dic];
                    
                    [self.modelArray addObject:model];
                }
                MyLog(@"tableViewData:%@",responseObject);
            }
            else{
                
                self.pageIndex -= 1;
                
            }
            [hud hideAnimated:YES];
            [self.tableView reloadData];
            [CommonClass endRefreshing:self.tableView];
        }];
    }
//    else{
//        [LSHttpEnclosureTool GET:LSScreenUserList parameters:@{@"cid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex)} resBlock:^(id responseObject) {
//            if (refresh) {
//                [self.modelArray removeAllObjects];
//            }
//            if (responseObject) {
//                for (NSDictionary * dict in responseObject[@"UserList"]) {
//                    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dict];
//                    //                    [dic setObject:@(self.queryType) forKey:@"queryType"];
//
//                    LSPersonalHomePageCharmModel *model = [LSPersonalHomePageCharmModel mj_objectWithKeyValues:dic];
//
//                    [self.modelArray addObject:model];
//                }
//                MyLog(@"tableViewData:%@",responseObject);
//            }
//            else{
//
//                self.pageIndex -= 1;
//
//            }
//            [hud hideAnimated:YES];
//            [self.tableView reloadData];
//            [CommonClass endRefreshing:self.tableView];
//        }];
//    }
    
    
    
}

//- (void)loadTableViewData:(BOOL)refresh{
//    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
//    //    hud.label.text=@"正在请求中...";
//    hud.mode=MBProgressHUDModeIndeterminate;
////    [self.modelArray removeAllObjects];
//
//    if (refresh) {
//
//        self.pageIndex = 0;
//    }else{
//
//        self.pageIndex += 1;
//    }
//
//    self.pageIndex = 0;
//    if (self.chooseTag == 0) {
//        [LSHttpEnclosureTool GET:LSPublishList parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex)} resBlock:^(id responseObject) {
//            if (refresh) {
//                [self.publishCycleArray removeAllObjects];
//            }
//            if (responseObject) {
//                for (NSDictionary * dict in responseObject[@"TopicList"]) {
//                    LSChatCircleModel *model = [LSChatCircleModel mj_objectWithKeyValues:dict];
//
//                    [self.publishCycleArray addObject:model];
//                }
//            }
//            else{
//
//                self.pageIndex -= 1;
//
//            }
//            //            MyLog(@"tableViewData:%@",responseObject);
//            [hud hideAnimated:YES];
//            [self.tableView reloadData];
//            [CommonClass endRefreshing:self.tableView];
//
//
//
//        }];
//
//    }else if (self.chooseTag == 1){
//
//        [LSHttpEnclosureTool GET:LSJoinList parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex)} resBlock:^(id responseObject) {
//            if (refresh) {
//                [self.joinCycleArray removeAllObjects];
//            }
//            if (responseObject) {
//                for (NSDictionary * dict in responseObject[@"JoinList"]) {
//                    LSChatCircleModel *model = [LSChatCircleModel mj_objectWithKeyValues:dict];
//                    [self.joinCycleArray addObject:model];
//                }
//            }
//            else{
//
//                self.pageIndex -= 1;
//
//            }
//            //            MyLog(@"tableViewData:%@",responseObject);
//            [hud hideAnimated:YES];
//            [self.tableView reloadData];
//            [CommonClass endRefreshing:self.tableView];
//        }];
//
//    }else if (self.chooseTag == 2){
//        self.queryType = 1;
//
//        [LSHttpEnclosureTool GET:LSUSerFans parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex),@"type":@(self.queryType)} resBlock:^(id responseObject) {
//            if (refresh) {
//                [self.modelArray removeAllObjects];
//            }
//            MyLog(@"tableViewData:%@",responseObject);
//            if (responseObject) {
//                for (NSDictionary * dict in responseObject[@"UserList"]) {
//                    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dict];
//                    [dic setObject:@(self.queryType) forKey:@"queryType"];
//                    LSPersonalHomePageCharmModel *model = [LSPersonalHomePageCharmModel mj_objectWithKeyValues:dict];
//
//                    [self.modelArray addObject:model];
//                    //                    MyLog(@"tableViewData:%@",dic);
//                }
//
//            }
//            else{
//
//                self.pageIndex -= 1;
//
//            }
//            [hud hideAnimated:YES];
//            [self.tableView reloadData];
//            [CommonClass endRefreshing:self.tableView];
//        }];
//
//    }else{
//        self.queryType = 2;
//
//        [LSHttpEnclosureTool GET:LSUSerFans parameters:@{@"cid":self.userCid,@"loginCid":[LSAccountArchive account].Cid,@"pageIndex":@(self.pageIndex),@"type":@(self.queryType)} resBlock:^(id responseObject) {
//            if (refresh) {
//                [self.modelArray removeAllObjects];
//            }
//            if (responseObject) {
//                for (NSDictionary * dict in responseObject[@"UserList"]) {
//                    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dict];
//                    [dic setObject:@(self.queryType) forKey:@"queryType"];
//                    MyLog(@"tableViewData -- %@",dic);
//                    LSPersonalHomePageCharmModel *model = [LSPersonalHomePageCharmModel mj_objectWithKeyValues:dic];
//
//                    [self.modelArray addObject:model];
//                }
//            }
//            else{
//
//                self.pageIndex -= 1;
//
//            }
//            [hud hideAnimated:YES];
//            [self.tableView reloadData];
//            [CommonClass endRefreshing:self.tableView];
//        }];
//    }
//
//
//
//}

//- (void)loadMoreTableViewData{
//    [self loadTableViewData:NO];
//}

//给topUI赋值
- (void)setData:(NSDictionary *)userindexInfo{
    NSArray * array =  @[[NSString stringWithFormat:@"发布的话题\n(%@)",userindexInfo[@"TopicPublishCount"]],[NSString stringWithFormat:@"参与的话题\n(%@)",userindexInfo[@"TopicJoinCount"]],[NSString stringWithFormat:@"关注\n(%@)",userindexInfo[@"AttentionsCount"]],[NSString stringWithFormat:@"粉丝\n(%@)",userindexInfo[@"FansCount"]]];
    headView.sortView.dataArray = array.mutableCopy;
    headView.dict = userindexInfo;
//    headView.attentionBu.selected = userindexInfo[@"IsAttended"];
    //    [headView.bottomArray addObjectsFromArray:@[[NSString stringWithFormat:@"发布的话题\n(%@)",userindexInfo[@"TopicPublishCount"]],[NSString stringWithFormat:@"参与的话题\n(%@)",userindexInfo[@"TopicJoinCount"]],[NSString stringWithFormat:@"关注\n(%@)",userindexInfo[@"AttentionsCount"]],[NSString stringWithFormat:@"粉丝\n(%@)",userindexInfo[@"FansCount"]]]];
}

#pragma mark - YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
{
    
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    //    hud.label.text=@"正在请求中...";
    hud.mode=MBProgressHUDModeIndeterminate;
    if (index == 0) {
        MyLog(@"举报");
        
        [hud hideAnimated:YES afterDelay:1.5f];
        //    __weak ViewController *weakSelf = self;
        
        /*延迟执行时间2秒*/
        dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC));
        dispatch_after(delayTime, dispatch_get_main_queue(), ^{
            //        [weakSelf delayMethod];
            [MBProgressHUD showOnlyMessage:@"举报成功，后台工作人员开始审核举报内容！" afterDelay:1.5f];
        });
    }else if (index == 1){
        MyLog(@"拉黑");
        [hud hideAnimated:YES afterDelay:1.5f];
        [LSHttpEnclosureTool POST:LSAddUserScreenUser parameters:@{@"usercid":self.userCid,@"loginUsercid":[LSAccountArchive account].Cid} resBlock:^(id responseObject) {
            if (responseObject) {
                
                MyLog(@"tableViewData:%@",responseObject);
                MyLog(@"responseObject --- %@",responseObject);
                [self loadTopViewData];
                [self loadTableViewData:YES];
                [notifiCenter postNotificationName:@"LOADCIRCLEDATA" object:nil];
                if (self.OtherAttentionBlock) {
                    self.OtherAttentionBlock();
                }
                [hud hideAnimated:YES];
                [MBProgressHUD showOnlyMessage:@"拉黑成功！" afterDelay:1.5f];
                [CommonClass endRefreshing:self.tableView];
            }
            else{
                [hud hideAnimated:YES];
                [CommonClass endRefreshing:self.tableView];
                [MBProgressHUD showOnlyMessage:@"拉黑失败！" afterDelay:1.5f];
            }
            
            
        }];
        
        
        
        
        [self dismissViewController];
    }
    
    
    
}

#pragma mark 🔥 tableViewDelegate tableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    if (self.chooseTag == 0) {
//        return self.publishCycleArray.count;
//    }
//    if (self.chooseTag == 1) {
//        return self.joinCycleArray.count;
//    }
    return self.modelArray.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.chooseTag==0) {
//        id  model = self.publishCycleArray[indexPath.row];
        id  model = self.modelArray[indexPath.row];
        return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LSChatCircleCell class] contentViewWidth:[tableView cellContentViewWith]];
    }else if (self.chooseTag == 1){
        
//        id model = self.joinCycleArray[indexPath.row];
        id  model = self.modelArray[indexPath.row];
        return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LSChatCirclePartakeCell class] contentViewWidth:[tableView cellContentViewWith]];
    }
    return 70;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.chooseTag==0) {
        
        LSChatCircleCell *cell=[LSChatCircleCell ChatCircleTableViewCellByTableView:tableView];
//        LSChatCircleModel * model = self.publishCycleArray[indexPath.row];
        LSChatCircleModel * model = self.modelArray[indexPath.row];
        cell.reportBu.hidden = YES;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.isShow = YES;
        cell.model = model;
        return cell;
    }else if (self.chooseTag==1){
        
        LSChatCirclePartakeCell * cell = [LSChatCirclePartakeCell ChatCirclePartakeTableViewCellByTableView:tableView];
//        LSChatCircleModel * model = self.joinCycleArray[indexPath.row];
        LSChatCircleModel * model = self.modelArray[indexPath.row];
        cell.model = model;
        cell.attentionBu.hidden = YES;
        return cell;
        
    }
    else{
        
        LSPersonalHomePageCharmCell *cell=[LSPersonalHomePageCharmCell PersonalHomePageCharmCellByTableView:tableView];
        LSPersonalHomePageCharmModel *model = self.modelArray[indexPath.row];
        cell.attentionBu.hidden = YES;
        cell.model = model;
        cell.delegate = self;
        return cell;
    }
    
    
    return nil;
}


//- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    if (self.chooseTag < 2) {
//        return 10;
//    }else{
//
//        return self.modelArray.count;
//    }
//
//}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    LSChatCircleModel * model = self.modelArray[indexPath.row];
//    ConversationDetailController *detailVC=[[ConversationDetailController alloc]init];
//    if (self.chooseTag == 0) {
//        detailVC.TopicId = model.Id;
//    }else if (self.chooseTag == 1){
//        detailVC.TopicId = model.TopicId;
//    }
//    detailVC.cid = _tokenStr;
//    [self.navigationController pushViewController:detailVC animated:YES];
    if (self.chooseTag == 0) {
//        LSChatCircleModel * model = self.publishCycleArray[indexPath.row];
        LSChatCircleModel * model = self.modelArray[indexPath.row];
        ConversationDetailController *detailVC=[[ConversationDetailController alloc]init];
        
        detailVC.TopicId = model.Id;
        detailVC.cid = self.userCid;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    else if (self.chooseTag == 1) {
//        LSChatCircleModel * model = self.joinCycleArray[indexPath.row];
        LSChatCircleModel * model = self.modelArray[indexPath.row];
        ConversationDetailController *detailVC=[[ConversationDetailController alloc]init];
        
        detailVC.TopicId = model.TopicId;
        detailVC.cid = self.userCid;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    else{
        KWeakSelf(self);
        LSPersonalHomePageCharmModel *model = self.modelArray[indexPath.row];
        
        if ([model.Cid isEqualToString:[LSAccountArchive account].Cid]) {
            MyLog(@"点自己");
            LSPersonalHomePageVController *homePageVC=[[LSPersonalHomePageVController alloc]init];
            homePageVC.userCid = [LSAccountArchive account].Cid;
            [weakself.navigationController pushViewController:homePageVC animated:YES];
        }else{
            LSOtherHomePageViewController *OHVC = [[LSOtherHomePageViewController alloc] init];
            OHVC.userCid = model.Cid;
            [weakself.navigationController pushViewController:OHVC animated:YES];
        }
    }
}


//#pragma mark 🔥 LSPersonalHomePageCharmCellDelagate
//- (void)attentionEvent:(UIButton *)sender CidString:(NSString *)string{
//
//}
#pragma mark 🔥 事件
- (void)clickReportBu:(UIButton *)sender{
    [YBPopupMenu showRelyOnView:sender titles:@[@"举报",@"拉黑"] icons:nil menuWidth:120 delegate:self];
}
-(void)segmentSortButtonEvent:(NSInteger)tag{
    switch (tag) {
        case 0:
            self.chooseTag=0;
            break;
        case 1:
            self.chooseTag=1;
            break;
        case 2:
            self.chooseTag=2;
            break;
        case 3:
            self.chooseTag=3;
            break;
            
        default:
            break;
    }
    
    [self loadTableViewData:YES];
    
}
- (void)EditIntroduceEvent{
    LSEditIntroduceViewController *EIVC = [[LSEditIntroduceViewController alloc] init];
    EIVC.PersonalDataChangedBlock = ^{
        [headView addFasleData];
//        if (self.PersonalDataChangedBlock) {
//            self.PersonalDataChangedBlock();
//        }
    };
    [self presentViewController:EIVC animated:YES completion:nil];
}

-(void)dismissViewController{
    //    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 🔥 UI
-(void)initTopUIWithData:(NSDictionary *)userInfo{
    self.chooseTag=0;
    headView=[[LSPersonalHomePageHeadView alloc]initWithFrame:CGRectMake(0,0, LSScreenWidth, 240+LSStatusBarHeight)];
    headView.bottomArray = @[@"发布的话题\n(0)",@"参与的话题\n(0)",@"关注\n(0)",@"粉丝\n(0)"];
    MyLog(@"bottomArray --- %@",headView.bottomArray);
//    headView.attentionBu.hidden = YES;
    [headView.introduceBu setImage:nil forState:UIControlStateNormal];
    headView.introduceBu.userInteractionEnabled = NO;
    headView.headImgBu.userInteractionEnabled = NO;
    NSArray * array =  @[[NSString stringWithFormat:@"发布的话题\n(%@)",userInfo[@"TopicPublishCount"]],[NSString stringWithFormat:@"参与的话题\n(%@)",userInfo[@"TopicJoinCount"]],[NSString stringWithFormat:@"关注\n(%@)",userInfo[@"AttentionsCount"]],[NSString stringWithFormat:@"粉丝\n(%@)",userInfo[@"FansCount"]]];
    headView.sortView.dataArray = array.mutableCopy;
    headView.dict = userInfo;

    
    __weak typeof(self) weakSelf = self;
    
    
    headView.sortView.butonActionBlock = ^(NSInteger tag) {
        [weakSelf segmentSortButtonEvent:tag];
    };
    headView.AttentionActionBlock = ^(UIButton *sender) {
//        if (![LSAccountArchive isLogin]){
//            LSLoginVController *loginVC=[[LSLoginVController alloc]init];
//            [weakSelf presentRootViewController:loginVC animated:YES completion:nil];
////            loginVC.loginSuccessBlock = ^{
////                [self.mineView addControlData];
////            };
//        }else{
            sender.enabled = NO;
            
            [LSHttpEnclosureTool POST:LSUserAttention parameters:@{@"fanCid":[LSAccountArchive account].Cid,@"Cid":weakSelf.userCid} resBlock:^(id responseObject) {
                if (responseObject) {
                    MyLog(@"responseObject --- %@",responseObject);
                    [weakSelf loadTopViewData];
                    [weakSelf loadTableViewData:YES];
                    sender.enabled = YES;
                    [notifiCenter postNotificationName:@"LOADCIRCLEDATA" object:nil];
                    if (weakSelf.OtherAttentionBlock) {
                        weakSelf.OtherAttentionBlock();
                    }
                }
                sender.enabled = YES;
            }];
//        }
        
       
    };
    
    
    [self.view addSubview:headView];
    
    //    UIButton *backItem=[UIButton buttonWithType:UIButtonTypeCustom];
    //    backItem.frame=CGRectMake(15,LSStatusBarHeight+10,30, 30);
    //    [backItem setImage:[UIImage imageNamed:@"ReturnCustom"] forState:UIControlStateNormal];
    //    [backItem addTarget:self action:@selector(dismissViewController) forControlEvents:UIControlEventTouchUpInside];
    //    [backItem setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
    //    [headView addSubview:backItem];
    
    [self.view addSubview:self.tableView]; self.tableView.sd_layout.leftEqualToView(self.view).rightEqualToView(self.view).topSpaceToView(headView, 0).bottomEqualToView(self.view);
    
    
}



@end
